package com.yanqu.road.server.gameplayer.module.activity.tomb.service;

import com.google.protobuf.AbstractMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.pb.tomb.Tomb;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.tomb.TombModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.sync.message.SyncResponse;

import java.util.List;

public class TombUserTopPatronsServiceCmd implements IGameServiceCommand {
    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(request.getSenderId());
        if (onlinePlayer == null) {
            syncResponse.setErrorCode(GameErrorCode.E_ACTIVITY_NOT_OPEN);
            return syncResponse;
        }
        List<Tomb.PartnerTemp> partnerList = onlinePlayer.getModule(TombModule.class).getPartnerList();
        Tomb.TombUserTopPatronsResp.Builder builder = Tomb.TombUserTopPatronsResp.newBuilder();
        builder.addAllList(partnerList);
        syncResponse.setResponseBuilder(builder);
        return syncResponse;
    }
}
